function alertPP(pstr) {
	getGuoJihua(pstr);
}
var xmlHttpMsg;
function getGuoJihua(msgV) {
	var url = "ajaxCommon.pk?msgV=" + encodeURIComponent(msgV) + "&type=guojihua";
	if (window.ActiveXObject) {
		xmlHttpMsg = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		xmlHttpMsg = new XMLHttpRequest();
	}

	xmlHttpMsg.onreadystatechange = funget;
	xmlHttpMsg.open("post", url, true);
	xmlHttpMsg.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8'); 
	//xmlHttpMsg.setRequestHeader('Content-Type', 'text/html;charset=UTF-8'); 
	xmlHttpMsg.send(null);
}
function funget() {

	if (xmlHttpMsg.readyState == 4 || xmlHttpMsg.readyState == "complete") {
		var msg = xmlHttpMsg.responseText;
		alert(msg);
	}
}
/**
 * 检验字符串是否为空
* @param {String} 字符串
 * @return {bool} 是否为空
 */
function isEmpty(input)
{
	if( input==null ||  trim(input).length == 0 || input == 'null')
		return true;
	else
		return false;
}

/**
 * 没有扩展名的
 * @param imgName
 * @return
 */
function getImagePathNoKzm(imgName) {
	return "upload/image/" + imgName + ".jpg";
}
/**
* 判断输入变量是否包含特殊字符
* 特殊字符：~ ! # $ % ^ & * ( ) - _ + = [ ] { } | \ ; : ' " , / < > ? <
* @param {String} 要检查的变量值
* @return {bool} 是否包含特殊字符
*/
function containSpecial( s )
{
	var containSpecial = RegExp(/[(\ )(\~)(\!)(\#)(\$)(\%)(\^)(\*)(\()(\))(\-)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\/)(\<)(\>)(\?)(\)]+/);
	return ( containSpecial.test(s) );
}

/**
* 若为null则替换为指定的字符串
* @param {String} 要测试的字符串
* @param {String} 为空时替换的字符串
* @return {String} 
*/
function nvl(s,replaceString)
{
	if ( isEmpty(s) )
		return replaceString;
	else
		return s;
} 

/**
* 将页面中或指定表格ID的所有checkbox置为选中状态或全不选状态
* @param {bool} choose: true选中；false不选
* @param {string} tableID:要指定的表格ID
*/
function selectAll(choose,tableID)
{
	var allCheck;
	if (arguments.length == 1) {
       allCheck =  document.getElementsByTagName("input");
    }else{
	   allCheck =  document.getElementById(tableID).getElementsByTagName("input");
    }
	 
	for(var i=0; i<allCheck.length; i++){
		var tagBody = allCheck[i];
		if (tagBody.getAttribute("type") == "checkbox")
		{
			tagBody.checked= choose;
		}
	}
}

/**
* 取得页面中的所有选中的checkbox的id列表
* @return {String} 以'|'分隔的选中id，如果没有选中任何checkbox则返回空串
*/
function getCheckList()
{	
	var checkList = '';
	var allCheck = document.getElementsByTagName("input");
	for(var i=0; i<allCheck.length; i++)
	{
		var tagBody = allCheck[i];
		if (tagBody.getAttribute("type") == "checkbox")
		{
			if ( tagBody.checked && !isEmpty(tagBody.id) )
			{
				checkList += tagBody.id  + '|';
			}
		}
	}
	return checkList;
}


/**
* 取得指定的radio按钮的选中值
* @param {String} radio按钮ID
* @return {String} radio按钮的选中值
*/
function getRadioValue(radioName)
{	
	var radioList = document.getElementsByName(radioName);
	for (var i = 0; i < radioList.length; i++)
	{
		if( radioList[i].checked == true )
		{
			return radioList[i].value;
		}
	}
}

function isDate(param) {
	var pattern = /^\d+$/;
	if ( param.length != 8 ) {
		return false;
	}
	if(!pattern.test(param)) {
		return false;
	}
	sYear = param.substring( 0, 4 );
	sMonth = param.substring( 4, 6 );
	sDay = param.substring( 6, 8 );
	if ( ( eval( sMonth ) < 1 ) || ( eval( sMonth )  > 12 ) ) {
		return false;
	}
	var leapYear = ((( sYear % 4 == 0 ) && ( sYear % 100 != 0 )) || ( sYear % 400 == 0 )) ? true : false;
	var monthDay = new Array(12);
	monthDay[0] = 31;
	monthDay[1] = leapYear ? 29 : 28;
	monthDay[2] = 31;
	monthDay[3] = 30;
	monthDay[4] = 31;
	monthDay[5] = 30;
	monthDay[6] = 31;
	monthDay[7] = 31;
	monthDay[8] = 30;
	monthDay[9] = 31;
	monthDay[10] = 30;
	monthDay[11] = 31;
	if ( ( eval( sDay ) < 1 ) || ( eval( sDay )  > monthDay[eval(sMonth)-1] ) ) {
		return false;
	}
	return true;
}

/**
 * 检查日期选择的格式及区间
 */
function checkDate(beginDate,endDate){
	if (! isDate(beginDate)) {
		alert("起始日期不正确");
		beginDate.focus();
		return true;
	}
	if (! isDate(endDate)) {
		alert("终止日期不正确");
		beginDate.focus();
		return true;
	}
	if((beginDate)>(endDate)){
		alert("截止日期应大于或等于起始日期,请重新输入");
		return true;
	}
	if (parseInt(endDate, 10) < parseInt(beginDate, 10) || ! dateInterval(beginDate,endDate, 90)) {
		alert("终止日期应在起始日期之后90天内");
		return true;
	}
}

function isDate1(dateInput){
	var inputYear = dateInput.substring( 0, 4 );
	var inputMonth = parseInt(dateInput.substring( 4, 6 ));
	var dateTest = new Date(inputYear,inputMonth);
	var testYear = dateTest.getFullYear();
	var testMonth = dateTest.getMonth();
	var isValidateDate = (inputYear == testYear && inputMonth == testMonth );
	return isValidateDate;
}

/**
* 去掉字符串前后的空格
* @param {String} 字符串
* @return {String} 去除空格后的字符串
*/
function trim(input) {
	return input.replace(/(^\s*)|(\s*$)/g, "");
}

/**
* 检查时间间隔是否在规定间隔之内
* @param {String} 开始日期
* @param {String} 结束日期
* @param {Integer} 间隔，单位为天
* @return {bool} 是否在规定间隔之内
*/
function dateInterval(startDate,endDate,interval) {
	var date1 = new Date(eval(startDate.substring(0,4)),eval(startDate.substring(4,6))-1,eval(startDate.substring(6,8)));
	var date2 = new Date(eval(endDate.substring(0,4)),eval(endDate.substring(4,6))-1,eval(endDate.substring(6,8)));
	if ( ( date2 - date1 ) / 86400000 > eval(interval) - 1 )
		return false;
	return true;
}

/**
* 控制text域的最大输入长度
* 用法：onblur="checkLength(this,要控制的长度);"
* @param {Object} text对象
* @param {Integer} 要控制的长度
*/
function checkLength(v,l){
	var s = v.value;
	var totalLength = 0;
	var charCode;
	for(i=0;i<s.length;i++)
	{
		charCode = s.charCodeAt(i);
		if (charCode < 0x007f) {
			totalLength ++;
		} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
			totalLength += 2;
		} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
			totalLength += 3;
		}
    }
	if( l>=totalLength )
	{
		return true;
	}
	else
	{
		//alert("该输入项插入值过长！最多输入"+l+"个字节");
		v.value = "";
		v.focus();
		return false;
	}
}

function alterButton(acceptBtId,ipt){
	var accBtn = document.getElementById(acceptBtId);
	if(accBtn)
	if(ipt.value.length!=0){
		accBtn.disabled = true;
	}else{
		accBtn.disabled = false;
	}
}

/**
* 控制textarea域的最大输入长度
* 用法：onblur="checkAreaLength(this,要控制的长度);"
* @param {Object} textarea对象
* @param {Integer} 要控制的长度
*/
function checkAreaLength(v,l){
	var s= v.value;
	var totalLength = 0;
	var charCode;
	
	for(i=0;i<s.length;i++)
	{
		charCode = s.charCodeAt(i);
		if (charCode < 0x007f) {
			totalLength ++;
		} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
			totalLength += 2;
		} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
			totalLength += 3;
		}
        }
	
	if(totalLength>l){
		//alert("该输入项插入值过长！最多输入"+l+"个字节");  	
		v.value = "";
		v.focus();
		return false;
	}
	return true;
}

/**
 * 隐藏DIV
 * @param divFlag
 * @return
 */
function hiddenDiv(divFlag) {
	document.getElementById(divFlag).style.display = 'none';
}

/**
 * 显示DIV
 * @param divFlag
 * @return
 */
function showDiv(divFlag) {
	document.getElementById(divFlag).style.display = 'block';
}

/**
* 修改指定tag的样式
* @param {String} tag的id
* @param {String} 新的样式
*/
function changeClass(tagId,newClassName)
{
	document.getElementById(tagId).className = newClassName;
}

/**
* 更改一个对象的选中状态，可以用于radio和checkBox
* @param {String} 对象的ID
*/
function doCheck(objectID)
{
	var checkObj = document.getElementById(objectID);
	if(checkObj.checked){
		checkObj.checked = false;
	}else{
		checkObj.checked = true;
	}
}

/**
* 将yyyymmddhhmiss方式显示的日期转为中文显示
* @param {String} yyyymmddhhmiss格式的时间
*/
function getChineseDateTime(dateTime)
{
	if( isEmpty(dateTime) || dateTime.length < 14 )
	{
		return dateTime;
	}
	var returnDate = dateTime.substr(0,4)+"年"+dateTime.substr(4,2)+"月"+dateTime.substr(6,2)+"日";
	var returnTime = dateTime.substr(8,2)+":"+dateTime.substr(10,2)+":"+dateTime.substr(12,2);
	return  returnDate+returnTime; 
}

/**
* 检验日期是否符合YYYYMM的格式，是否合法
* @param {String} 日期字符串
* @return {bool} 是否是合法日期
*/
function isYearMonth(param) {
	var pattern = /^\d+$/;
	if ( param.length != 6 ) {
		return false;
	}
	if(!pattern.test(param)) {
		return false;
	}
	sYear = param.substring( 0, 4 );
	sMonth = param.substring( 4, 6 );
	if ( ( eval( sMonth ) < 1 ) || ( eval( sMonth )  > 12 ) ) {
		return false;
	}
	return true;
}

/**
* 高亮关键字
* @param {String} 搜索结果字符串
* @param {String} 搜索关键字
* @return {String} 关键字高亮的html字符串
*/
function highLightKeyword(content,key)
{
	var SPAN_BEGIN_TAG = '<span class="highLight">';
	var SPAN_END_TAG = '</span>';
	var htmlString = '';
	var searchStartPos = 0;
	while(true)
	{ 
		var keyStartPos = content.indexOf(key,searchStartPos);
		if( keyStartPos<0 )
		{
			htmlString += content.substring(searchStartPos);
			return htmlString;
		}
		var keyEndPos = keyStartPos+key.length;
		htmlString += content.substring(searchStartPos,keyStartPos);
		htmlString += SPAN_BEGIN_TAG;
		htmlString += key;
		htmlString += SPAN_END_TAG;
		searchStartPos = keyEndPos;
	}
}
/*
 * 根据json数据生成输入表单用的html
 * 示例：getInputHtmlFromJson({name:'mvmouse'},'test') = '<input type="hidden" name="test.name" value="mvmouse"/>'
 * @param {json} jsonInput
 * @param {String} input的name的前缀
 * @return {String} 生成的html 
 */
function getInputHtmlFromJson( jsonInput,namePrefix )
{
	var resultHtml = '';
	var prefixString ='<input type="hidden" name="'+namePrefix;
	for (var key in jsonInput ) 
	{
        var value = jsonInput[key];
        resultHtml += prefixString + key + '" value="'+value+'" />';
	}
	return resultHtml;
}

/*
 * 修改下拉单中内容
 */
function changeSelectItem(selectName,selectValue){
	var options=$(selectName).options;
	for(var i=0;i<options.length;i++){
		var optionValue=options[i].value.split("|");
		if(optionValue[0]==selectValue){
			options[i].selected=true;
			return true;
		}
	}
	return false;
}

/**
 *是否为规范的电话号码
 */
function isTelephone(s) {
	if(isEmpty(s) || !isInteger(s) || s.length > 12) {
		alert('电话号码必须为12位以内的数字！');
		return false;
	}
	return true;
}

//**************************************************************
//表现形式增加逗号
//Creation date: (2003-05-12) 
//@author: ecc-wangdong
//@version: 1.0
//@param：number
//   @param说明：
// 需转换数值 
//**************************************************************
function comma(number) {
	number = '' + number;
	if (number.length > 3) {
	var mod = number.length % 3;
	var output = (mod > 0 ? (number.substring(0,mod)) : '');
	for (i=0 ; i < Math.floor(number.length / 3); i++) {
	 if ((mod == 0) && (i == 0))
	  output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
	 else
	  output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
	}
	return (output);
	}
	else return number;
}

function isMoney(s) {
	v = rmoney(s);
	var a=/^[0-9]*(\.[0-9]{1,2})?$/;
	if(!a.test(v))
	{
		return false;
	}
	else
	{
		return true;
	}

}
//还原金额 
function rmoney(s) 
{ 
	return parseFloat(s.replace(/[^\d\.-]/g, "")); 
} 


function showIp(strIp) {
	var retStr = "";
	retStr = strIp.substring(0,len(strIp)/2 +3) + "***";
	return retStr;
}

function len(s) { 
	var l = 0; 
	var a = s.split(""); 
	for (var i=0;i<a.length;i++) { 
	if (a[i].charCodeAt(0)<299) { 
	l++; 
	} else { 
	l+=2; 
	} 
	} 
	return l; 
} 
var currentable;
function mouseOver(evt)
{
	evt = evt?evt:(window.event?window.event:null);
	currentable = evt.srcElement? evt.srcElement : evt.target;
	if(currentable.tagName=="TD")
	{
		currentable.className=currentable.parentNode.className;
		currentable.parentNode.className="result_over";
	}
}

function mouseOut(evt)
{
	evt = evt?evt:(window.event?window.event:null);
	currentable = evt.srcElement? evt.srcElement : evt.target;
	if(currentable.tagName=="TD")
		currentable.parentNode.className=currentable.className;
}

/**
* 清空一个表的内容
* @param {String} 表体的ID
*/
function cleanTableBody(tbodyName)
{
	var tbody  = document.getElementById(tbodyName);
	var rows=tbody.getElementsByTagName("TR");
	var size = rows.length;
	for(var i=0;i<size;i++)
	{
		tbody.deleteRow(0);
	}
}

//取js字符串的长度,比如"123"长度是3,"汉字"是4
function getByteNum(inputStr){
 	if(inputStr==null||inputStr=="") return 0;
 	var cnt = 0;
  	for(i=0;i<inputStr.length;i++) {
    		var c = inputStr.substr(i,1);
    		var ts = escape(c);
    		if(ts.substring(0,2) == "%u") {
      			cnt = cnt*1 + 2;
    		} else {
      			cnt = cnt*1 + 1;
    		}
    	}
    	return cnt;
	}
	
//取得Radio控键被选中的值,radioName为Radio的Name属性 Xuhao
function getRadioValue(radioName){
	var radObj=document.getElementsByName(radioName);
	var radValue="";
	for (var i=0;i<radObj.length;i++){
		if(radObj[i].checked){
			radValue=radObj[i].value;
			break;
		}
	}
	return radValue;
}

//选择值对应的Radio  Xuhao
function checkedRadio(radioObj,value){
	var radObj=document.getElementsByName(radioObj);
	for(var i=0;i<radObj.length;i++){
     	if(radObj[i].value==value){
     		radObj[i].checked=true;
     		break;
     	}     
     }
}


function showTime(strTime, e) {
	var retStr = strTime;
	var baseTime = "1970-1-1 08:00:00";
	if (e ==0 ) {
		retStr=DateAdd("l",strTime,baseTime)
	}
	else {
		etDate=DateDiff("l",baseTime,strTime)
	}
	retStr = retStr.format("yyyy-MM-dd hh:mm:ss"); 

	return retStr;
}

function showFmtTime(pStr) {
	var retStr = "";
	var retStr = pStr.substr(0, 4) + "-" + pStr.substr(4, 2) + "-" + pStr.substr(6, 2) + " " +  pStr.substr(8, 2) + ":" +  pStr.substr(10, 2);

	return retStr;
}
function DateAdd(interval,number,date){ 
	// date 可以是时间对象也可以是字符串，如果是后者，形式必须为: yyyy-mm-dd hh:mm:ss 其中分隔符不定。"2006年12月29日 16点01分23秒" 也是合法的
	number = parseInt(number);
	if (typeof(date)=="string"){
		date = date.split(/\D/);
		--date[1];
		eval("var date = new Date("+date.join(",")+")");
	}
	if (typeof(date)=="object"){
		var date = date
	}
	switch(interval){
		case "y": date.setFullYear(date.getFullYear()+number); break;
		case "m": date.setMonth(date.getMonth()+number); break;
		case "d": date.setDate(date.getDate()+number); break;
		case "w": date.setDate(date.getDate()+7*number); break;
		case "h": date.setHours(date.getHour()+number); break;
		case "n": date.setMinutes(date.getMinutes()+number); break;
		case "s": date.setSeconds(date.getSeconds()+number); break;
		case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
	} 
	return date;
}
//禁止刷新，回退 
function onKeyDown() 
{ 
	if ( (event.altKey) || ((event.keyCode == 8) && 
	(event.srcElement.type != "text" && 
	event.srcElement.type != "textarea" && 
	event.srcElement.type != "password")) || 
	((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) || 
	(event.keyCode == 116) ) { 
	event.keyCode = 0; 
	//event.returnValue = false; 
	} 
} 
document.onkeydown = onKeyDown;

//这个是禁用鼠标右键
function stop(){ 
	return true; 
} 
document.oncontextmenu=stop;


Date.prototype.format = function(format){ 
	var o = { 
	"M+" : this.getMonth()+1, //month 
	"d+" : this.getDate(), //day 
	"h+" : this.getHours(), //hour 
	"m+" : this.getMinutes(), //minute 
	"s+" : this.getSeconds(), //second 
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
	"S" : this.getMilliseconds() //millisecond 
	} 

	if(/(y+)/.test(format)) { 
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 

	for(var k in o) { 
	if(new RegExp("("+ k +")").test(format)) { 
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
	} 
	} 
	return format; 
} 


function getAfterDay(afDays) {
	var days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getYear();
	var afterDate = new Date(gyear, gmonth+1, gdate + afDays);
	return afterDate.getYear() + "-" + afterDate.getMonth() + "-" + afterDate.getDate();
}

function validate_email(field){
	with (field){
		var value;
		value = document.getElementById("email").value;
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2){
			return false;
		}else{
			return true;
		}
	}
}

function validate_mobile(filed){
    var mobile = filed.value;
    if(mobile == ""){
    	alertPP("手机号码为空");
        return true;           
    }
    if (containSpecial(mobile)) {
    	alertPP("手机号码有特殊字符");
    	return true;        
    }
    if(!mobile.match(/^[1]{1}[0-9]{10}$/)){
        alertPP("手机号码填写不正确");
        return true;        
    }        
}
